package com.oa.ylms.apps.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Date Transfer Tool
 */
public class DateUtil {
	public static Date toDate(String strDate) throws Exception {
		DateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sf.parse(strDate);

	}

	public static Date toDateWithoutHours(String strDate) throws Exception {
		DateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		return sf.parse(strDate);

	}

	public static String toString(Date date) throws RuntimeException {
		DateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sf.format(date);
	}

	public static String toStringWithoutHours(Date date)
			throws RuntimeException {
		DateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		return sf.format(date);
	}

	public static String getCurrentDate() throws Exception {
		DateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sf.format(new Date());
	}
}
